package com.deer.wms.base.system.web.task;

import com.deer.wms.base.system.model.task.TaskInfo;
import com.deer.wms.base.system.model.task.TaskInfoCriteria;
import com.deer.wms.base.system.model.task.TaskInfoDto;
import com.deer.wms.base.system.model.task.TaskInfoHistoryDto;
import com.deer.wms.base.system.service.task.TaskInfoHistoryService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.core.result.Result;
import com.deer.wms.common.core.result.ResultGenerator;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
/***
 *出库任务历史
 * @param
 * @author 李帅辰
 * @date 2020/9/25 14:24
 * @return
 */
@Controller
@RequestMapping("/in/billOutTaskInfoHistory")
public class BillOutTaskInfoHistoryController extends BaseController {
    @Autowired
    private TaskInfoHistoryService taskInfoHistoryService;
    private String prefix = "task";

    @RequiresPermissions("in:taskInfoHistory:view")
    @GetMapping("/page")
    public String taskInfo() {
        return prefix + "/taskInfoHistory";
    }

    /**
     * 查询任务列表
     */
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(TaskInfoCriteria taskInfoCriteria) {
        startPage();
        List<TaskInfoHistoryDto> list = taskInfoHistoryService.findList(taskInfoCriteria);
        return getDataTable(list);
    }


    /**
     * 查询出库历史任务列表
     */
    @PostMapping("/billOutFindList")
    @ResponseBody
    public TableDataInfo billOutfindList(TaskInfoCriteria taskInfoCriteria) {
        startPage();
        List<TaskInfoDto> list = taskInfoHistoryService.billOutfindList(taskInfoCriteria);
        return getDataTable(list);
    }

    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskInfoCriteria taskInfoCriteria) {

        List<TaskInfoDto> list = taskInfoHistoryService.billOutfindList(taskInfoCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(list, "出库历史作业");
    }
    /**
     * 导出列表
     */
    //@RequiresPermissions("in:billInMaster:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam String ids) {
        List<TaskInfoDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            TaskInfoCriteria b=new TaskInfoCriteria ();
            b.setBillId(Integer.parseInt(s));
            List<TaskInfoDto> list = taskInfoHistoryService.billOutfindList(b);
            for (TaskInfoDto bs:list
            ) {
                byIds.add(bs);
            }

        }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<TaskInfoDto> util = new ExcelUtil<TaskInfoDto>(TaskInfoDto.class);
        return util.exportExcel(byIds, "出库历史作业");
    }

    @PostMapping("/add")
    @ResponseBody
    public Result add(TaskInfo taskInfo) {
        taskInfoHistoryService.saveTaskInfoHistory(taskInfo);
        return ResultGenerator.genSuccessResult();
    }
}
